<template>
  <div class="app-container">
    <div v-show="active === 1">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="groupSearchForm" :model="search" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionCode" label="职位代码">
                <el-input v-model="search.positionCode" placeholder="职位代码" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionName" label="职位名称">
                <el-input v-model="search.positionName" placeholder="职位名称" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="orgName" label="组织名称">
                <el-input v-model="search.orgName" placeholder="组织名称" clearable />
              </el-form-item>
            </el-col>
            <!--<el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="areaType" label="业务范围">
                <r-select v-model="search.areaType" type="4503" placeholder="业务范围" clearable/>
              </el-form-item>
            </el-col>-->

            <div style="text-align:right">
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询
              </el-button>
              <el-button icon="el-icon-refresh" @click="resetForm('groupSearchForm')">重置
              </el-button>
            </div>
          </el-row>
        </el-form>
      </div>
      <!-- 用户列表 -->
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">职位信息</div>
          <div class="btnGroup">
            <el-button-group>
              <el-button type="primary" icon="el-icon-plus" @click="groupAdd">新增
              </el-button>
            </el-button-group>
          </div>
        </div>
        <BaseTable ref="groupTable" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle">
          <el-table-column type="index" label="序号" min-width="20"/>
          <el-table-column align="center" label="操作" min-width="70">
            <template slot-scope="scope">
              <el-tooltip class="item" content="编辑" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-edit-outline" @click="groupEdit(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="明细" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-document" @click="groupDetail(scope.row)"/>
              </el-tooltip>
              <el-tooltip class="item" content="删除" placement="bottom">
                <el-button type="text" style="font-size: 20px;" icon="el-icon-delete" @click="groupDelete(scope.row.POSITION_ID)"/>
              </el-tooltip>
            </template>
          </el-table-column>
          <el-table-column v-if="false" prop="ORG_POSITION_ID"/>
          <el-table-column prop="POSITION_CODE" label="职位代码" min-width="100"/>
          <el-table-column prop="POSITION_NAME" label="职位名称" min-width="100"/>
          <el-table-column prop="ORG_NAME" label="组织" min-width="100"/>
          <!--          <el-table-column :formatter="filterCode" prop="AREA_TYPE" label="业务范围" min-width="100" type="4503"/>-->
        </BaseTable>
      </div>
    </div>
    <!-- 集团新增div -->
    <div v-show="active === 1.1">
      <div class="searchform">
        <el-form ref="groupAddSearchForm" :model="groupAddSearch" :rules="rules" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionCode" label="职位代码">
                <el-input v-model="groupAddSearch.positionCode" placeholder="职位代码" maxlength="20" minlength="4" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionName" label="职位名称">
                <el-input v-model="groupAddSearch.positionName" placeholder="职位名称" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="组织" prop="orgName" >
                <departmentSelect
                  v-model="groupAddSearch.orgName"
                  :org-id.sync="groupAddSearch.orgId"
                  :org-name.sync="groupAddSearch.orgName"
                  @getDepartmentOrgTree="getDepartmentOrgTree" />
                <el-input v-if="false" v-model="groupAddSearch.organizationId" placeholder="组织ID" clearable/>
              </el-form-item>
            </el-col>
            <el-col v-if="groupAddSearch.orgId !='' && groupAddSearch.orgType == 16801003 " :xs="24" :sm="8" :md="6">
              <el-form-item label="职位级别" prop="positionLevel" >
                <r-select v-model="groupAddSearch.positionLevel" type="1017"/>
              </el-form-item>
            </el-col>
            <!--<el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="是否传电商" prop="isSyncBeidi" >
                <r-select v-model="groupAddSearch.isSyncBeidi" type="1004"/>
              </el-form-item>
            </el-col>-->
          </el-row>
        </el-form>
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="已分配角色" name="first">
          <div class="table">
            <div class="tableHead">
              <div class="btnGroup">
                <el-button-group>
                  <el-button type="primary" icon="el-icon-plus" @click="openRole">添加</el-button>
                </el-button-group>
              </div>
            </div>

            <BaseTableNoPage ref="groupAddTable1" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle">
              <el-table-column type="index" label="序号" min-width="20"/>
              <el-table-column align="center" label="操作" min-width="20">
                <template slot-scope="scope">
                  <el-tooltip class="item" content="删除" placement="bottom">
                    <el-button type="text" style="font-size: 20px;" icon="el-icon-delete" @click="groupAddTable1Delete(scope.$index, scope.row)"/>
                  </el-tooltip>
                </template>
              </el-table-column>
              <el-table-column prop="ROLE_CODE" label="角色代码" min-width="50"/>
              <el-table-column prop="ROLE_NAME" label="角色名称" min-width="50"/>
            </BaseTableNoPage>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button type="primary" @click="groupSave">保存</el-button>
        <el-button @click="clear">返回</el-button>
      </div>

    </div>
    <!-- 集团编辑div -->
    <div v-show="active === 1.2">
      <div class="searchform">
        <el-form ref="groupEditSearchForm" :model="groupEditSearch" :rules="rules" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionCode" label="职位代码">
                <el-input v-model="groupEditSearch.positionCode" disabled placeholder="职位代码" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionName" label="职位名称">
                <el-input v-model="groupEditSearch.positionName" placeholder="职位名称" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="组织" prop="orgName" >
                <departmentSelect
                  v-model="groupEditSearch.orgName"
                  :org-id.sync="groupEditSearch.orgId"
                  :org-name.sync="groupEditSearch.orgName"
                  @getDepartmentOrgTree="getDepartmentOrgEditTree" />
                <el-input v-if="false" v-model="groupEditSearch.organizationId" placeholder="组织ID" clearable/>
              </el-form-item>
            </el-col>
            <el-col v-if="groupEditSearch.orgId !='' && groupEditSearch.orgType == 16801003 " :xs="24" :sm="8" :md="6">
              <el-form-item label="职位级别" prop="positionLevel" >
                <r-select v-model="groupEditSearch.positionLevel" type="1017"/>
              </el-form-item>
            </el-col>
            <!--<el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="是否传电商" prop="isSyncBeidi" >
                <r-select v-model="groupEditSearch.isSyncBeidi" type="1004"/>
              </el-form-item>
            </el-col>-->
          </el-row>
        </el-form>
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="已分配角色" name="first">
          <div class="table">
            <div class="tableHead">
              <div class="btnGroup">
                <el-button-group>
                  <el-button type="primary" icon="el-icon-plus" @click="openRole">添加</el-button>
                </el-button-group>
              </div>
            </div>

            <BaseTableNoPage ref="groupEditTable1" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle">
              <el-table-column type="index" label="序号" min-width="20"/>
              <el-table-column align="center" label="操作" min-width="20">
                <template slot-scope="scope">
                  <el-tooltip class="item" content="删除" placement="bottom">
                    <el-button type="text" style="font-size: 20px;" icon="el-icon-delete" @click="groupEditTable1Delete(scope.$index, scope.row)"/>
                  </el-tooltip>

                </template>
              </el-table-column>
              <el-table-column prop="ROLE_CODE" label="角色代码" min-width="50"/>
              <el-table-column prop="ROLE_NAME" label="角色名称" min-width="50"/>
            </BaseTableNoPage>
          </div>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button type="primary" @click="editSave">保存</el-button>
        <el-button @click="clear">返回</el-button>
      </div>

    </div>
    <!-- 集团明细div -->
    <div v-show="active === 1.3">
      <div class="searchform">
        <el-form ref="groupViewSearchForm" :model="groupEditSearch" size="mini" label-width="90px">
          <el-row :gutter="6">
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionCode" label="职位代码">
                <el-input v-model="groupEditSearch.positionCode" disabled placeholder="职位代码" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item prop="positionName" label="职位名称">
                <el-input v-model="groupEditSearch.positionName" disabled placeholder="职位名称" clearable />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="组织" prop="orgName" >
                <el-input v-model="groupEditSearch.orgName" placeholder="组织" clearable disabled/>
                <!--<departmentSelect @getDepartmentOrgTree="getDepartmentOrgTree" v-model="groupEditSearch.orgName" :ORG_ID.sync="groupEditSearch.orgId"-->
                <!--:ORG_NAME.sync="groupEditSearch.orgName"  />-->
                <el-input v-if="false" v-model="groupEditSearch.organizationId" placeholder="组织ID" clearable/>
              </el-form-item>
            </el-col>
            <el-col v-if="groupEditSearch.orgId !='' && groupEditSearch.orgType == 16801003 " :xs="24" :sm="8" :md="6">
              <el-form-item label="职位级别" prop="positionLevel" >
                <r-select v-model="groupEditSearch.positionLevel" disabled type="1017"/>
              </el-form-item>
            </el-col>
            <!--<el-col :xs="24" :sm="8" :md="6">
              <el-form-item label="是否同步电商" prop="isSyncBeidi" >
                <r-select v-model="groupEditSearch.isSyncBeidi" disabled type="1004"/>
              </el-form-item>
            </el-col>-->
          </el-row>
        </el-form>
      </div>
      <el-tabs v-model="activeName">
        <el-tab-pane label="已分配角色" name="first">
          <BaseTableNoPage ref="groupDetailTable1" @chaneg-size="changeSizeHandle" @chaneg-page="changePageHandle">
            <el-table-column type="index" label="序号" min-width="20"/>
            <el-table-column prop="ROLE_CODE" label="角色代码" min-width="50"/>
            <el-table-column prop="ROLE_NAME" label="角色名称" min-width="50"/>
          </BaseTableNoPage>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <!-- <el-button @click='editSave' type="primary">保存</el-button> -->
        <el-button @click="clear">返回</el-button>
      </div>

    </div>
    <!-- 弹框 -->
    <el-dialog v-dialogDrag :visible.sync="dialogVisible" title="角色模板选择" width="70%">
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form ref="searchForm" :inline="true" :model="roleSearch" size="mini" label-width="100px">
          <el-form-item prop="roleCode" label="角色代码">
            <el-input v-model="roleSearch.roleCode" placeholder="角色代码" clearable />
          </el-form-item>
          <el-form-item prop="roleName" label="角色名称">
            <el-input v-model="roleSearch.roleName" placeholder="角色名称" clearable />
          </el-form-item>
          <div style="text-align:center">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchRole">查询
              </el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置
              </el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <!-- 用户列表 -->
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">角色信息</div>
        </div>
        <el-table
          v-loading="load"
          ref="roleTable"
          :data="list"
          tooltip-effect="dark"
          style="width: 100%"
          stripe
          border
          @selection-change="handleSelectionChange">
          <el-table-column type="index" label="序号" width="50"/>
          <el-table-column type="selection" width="40"/>
          <el-table-column prop="ROLE_CODE" label="角色代码" min-width="50"/>
          <el-table-column prop="ROLE_NAME" label="角色名称" min-width="50"/>
        </el-table>
        <!-- 分页 -->
        <Pagination :data="page" @change-size="handleSizeChange" @change-page="handleCurrentChange" />
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <!-- <span slot="footer" class="dialog-footer"> -->
        <el-button type="primary" @click="req">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>

        <!-- </span> -->
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getPositionAuthList,
  getPositionAuthRoleModelList,
  getPositionAuthRoleList,
  groupSavePositionAuth,
  editSavePositionAuth,
  deleteInfoById
} from '@/api/admin/auth/gms/positionAuth'
import departmentSelect from '@/views/admin/org/gms/departmentSelect'
import Pagination from '@/components/Pagination'
import BaseTable from '@/components/BaseTable'
import BaseTableNoPage from '@/components/BaseTable/BaseTableNoPage'
import formMixins from '@/mixins/formMixins'
import _ from 'lodash'
import { systemCode } from '@/utils/validator'
import rSelect from '@/components/Select/Select'

export default {
  name: 'GmsPositionAuth',
  components: {
    BaseTable,
    BaseTableNoPage,
    Pagination,
    departmentSelect,
    rSelect
  },
  mixins: [formMixins],
  data() {
    const validatePositionCode = (rule, value, callback) => {
      if (value === undefined || value === '' || value === null) {
        callback(new Error('请输入职位代码'))
      } else {
        systemCode(rule, value, callback)
      }
    }

    return {
      type2: '',
      active: 1,
      activeName: 'first',
      form: {},
      list: [],
      load: false,
      page: {},
      multipleSelection: [],
      returnList: [],
      search: {
        limit: 10,
        pageNum: 1,
        positionCode: '',
        positionName: '',
        areaType: '',
        orgName: '',
        dataSource: '10451003',
        dataType: '10461002'

      },
      groupAddSearch: {
        positionCode: '',
        positionName: '',
        positionLevel: '',
        orgName: '',
        orgId: '',
        orgType: '',
        isSyncBeidi: 10041002,
        organizationId: ''
      },
      groupEditSearch: {
        positionId: '',
        positionCode: '',
        positionName: '',
        positionLevel: '',
        orgName: '',
        orgId: '',
        orgType: '',
        isSyncBeidi: '',
        organizationId: ''
      },
      roleSearch: {
        limit: 10,
        pageNum: 1,
        roleCode: '',
        roleName: '',
        isDealer: 'false'
      },
      dialogVisible: false,
      rules: {
        positionCode: [{
          required: true,
          // message: '请输入职位名称',
          validator: validatePositionCode,
          trigger: 'blur'
        }],
        positionName: [{
          required: true,
          message: '请输入职位名称'
        }],
        positionLevel: [{
          required: true,
          message: '请输入职位级别'
        }],
        orgName: [{
          required: true,
          message: '请输入组织名称'
        }],
        isSyncBeidi: [{
          required: true,
          message: '该值必填'
        }]
      }

    }
  },
  computed: {},
  watch: {
    '$route.params.positionName'(val, oldval) {
      const positionName = this.$route.params.positionName
      if (positionName) {
        this.search.positionName = positionName
        this.searchHandle()
      }
    }
  },
  mounted() {
    const positionName = this.$route.params.positionName
    if (positionName) this.search.positionName = positionName
    this.searchHandle()
  },
  methods: {
    // 查询
    searchHandle() {
      const table = this.$refs['groupTable']
      const search = _.extend(this.search)
      table.wait()
      getPositionAuthList(search).then(res => {
        table.complete().filData(res)
      }).catch(err => {
        table.complete()
      })
    },
    // 查询角色模板选择列表
    openRole() {
      this.dialogVisible = true
      this.searchRole()
    },
    searchRole() {
      this.load = true
      getPositionAuthRoleModelList(this.roleSearch).then(res => {
        this.list = res.rows
        this.page = res
        this.load = false
      }).catch(err => {
        this.load = false
      })
    },
    // 集团新增
    groupAdd() {
      this.active = 1.1
      this.type2 = 'add'
      this.$nextTick(() => {
        this.$refs.groupAddSearchForm.resetFields()
      })
    },
    // 集团编辑
    groupEdit(data) {
      this.active = 1.2
      this.type2 = 'eddit'
      const groupEditTable1 = this.$refs['groupEditTable1']
      const id = data.POSITION_ID
      const positionCode = data.POSITION_CODE
      const positionName = data.POSITION_NAME
      const organizationId = data.ORG_ID
      const orgName = data.ORG_NAME
      this.groupEditSearch.orgType = data.ORG_TYPE
      this.groupEditSearch.positionId = id
      this.groupEditSearch.positionCode = positionCode
      this.groupEditSearch.positionName = positionName
      this.groupEditSearch.positionLevel = data.POSITION_LEVEL
      this.groupEditSearch.organizationId = organizationId
      this.groupEditSearch.orgName = orgName
      this.groupEditSearch.orgId = organizationId
      getPositionAuthRoleList(id).then(res => {
        groupEditTable1.complete().filData(res)
      }).catch(err => {
        groupEditTable1.complete()
      })
    },
    // 集团明细
    groupDetail(data) {
      this.active = 1.3
      const groupDetailTable1 = this.$refs['groupDetailTable1']
      const id = data.POSITION_ID
      const positionCode = data.POSITION_CODE
      const positionName = data.POSITION_NAME
      const organizationId = data.ORG_ID
      const orgName = data.ORG_NAME
      this.groupEditSearch.orgType = data.ORG_TYPE
      this.groupEditSearch.organizationId = organizationId
      this.groupEditSearch.orgName = orgName
      this.groupEditSearch.orgId = organizationId
      this.groupEditSearch.positionId = id
      this.groupEditSearch.positionCode = positionCode
      this.groupEditSearch.positionName = positionName
      this.groupEditSearch.positionLevel = data.POSITION_LEVEL
      getPositionAuthRoleList(id).then(res => {
        groupDetailTable1.complete().filData(res)
      }).catch(err => {
        groupDetailTable1.complete()
      })
    },
    groupDelete(id) {
      this.$confirm('是否删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteInfoById(id).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.searchHandle()
          })
        })
        .catch(err => {
        })
    },
    // 删除
    groupAddTable1Delete(index, row) {
      const groupAddTable1 = this.$refs.groupAddTable1
      groupAddTable1.delete(index)
    },
    groupEditTable1Delete(index, row) {
      const groupEditTable1 = this.$refs.groupEditTable1
      groupEditTable1.delete(index)
    },
    // 角色列表选择
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    req() {
      const val = this.multipleSelection
      if (val.length === 0) {
        this.$message({
          type: 'info',
          message: '请选择数据!'
        })
        return false
      }
      const SelectListed = this.$refs.groupAddTable1.data()
      if (!SelectListed.length === 0 && this.type2 === 'add') {
        for (let i = 0; i < SelectListed.length; i++) {
          for (let j = 0; j < val.length; j++) {
            if (SelectListed[i].ROLE_ID === val[j].ROLE_ID) {
              this.$message({
                type: 'info',
                message: '信息已存在，请重新选择!'
              })
              return
            }
          }
        }
      }
      const SelectListed1 = this.$refs.groupEditTable1.data()
      if (!SelectListed1.length === 0 && this.type2 === 'eddit') {
        for (let i = 0; i < SelectListed1.length; i++) {
          for (let j = 0; j < val.length; j++) {
            if (SelectListed1[i].ROLE_ID === val[j].ROLE_ID) {
              this.$message({
                type: 'info',
                message: '信息已存在，请重新选择!'
              })
              return
            }
          }
        }
      }
      const groupAddTable1 = this.$refs.groupAddTable1
      const groupEditTable1 = this.$refs.groupEditTable1
      groupAddTable1.rolePush(val)
      groupEditTable1.rolePush(val)
      this.roleSearch.roleCode = ''
      this.roleSearch.roleName = ''
      this.dialogVisible = false
      this.$message({
        type: 'success',
        message: '添加成功!'
      })
      this.searchHandle()
    },
    // 角色选择分页
    handleSizeChange(size) {
      this.roleSearch.limit = size
      this.searchRole()
    },
    handleCurrentChange(page) {
      this.roleSearch.pageNum = page
      this.searchRole()
    },
    // 集团保存
    groupSave() {
      this.$refs['groupAddSearchForm'].validate((valid) => {
        if (valid) {
          if (this.groupAddSearch.organizationId === '' || this.groupAddSearch.organizationId === null || this.groupAddSearch.organizationId === undefined) {
            this.$message({
              type: 'info',
              message: '组织不能为空!'
            })
            return false
          }
          const roleGmsSelectList = this.$refs.groupAddTable1.data()
          roleGmsSelectList.forEach(item => {
            item['roleId'] = item.ROLE_ID
            item['roleName'] = item.ROLE_NAME
          })
          const departGmsList = []
          const data = {
            dataSource: '10451003',
            dataType: '10461002',
            positionCode: this.groupAddSearch.positionCode,
            positionName: this.groupAddSearch.positionName,
            organizationId: this.groupAddSearch.organizationId, // 组织ID
            positionLevel: this.groupAddSearch.positionLevel,
            isSyncBeidi: this.groupAddSearch.isSyncBeidi,
            departGmsList: departGmsList,
            roleGmsSelectList: roleGmsSelectList
          }
          groupSavePositionAuth(data).then(res => {
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            this.active = 1
            this.searchHandle()
          }).catch(err => {
            this.$message({
              type: 'error',
              message: err.response.data.errorMsg
            })
            return false
          })
        } else {
          this.$message({
            type: 'info',
            message: '请填写必填项!'
          })
          return false
        }
      })
    },
    // 编辑保存
    editSave() {
      this.$refs['groupEditSearchForm'].validate((valid) => {
        if (valid) {
          const roleGmsSelectList = this.$refs.groupEditTable1.data()
          roleGmsSelectList.forEach(item => {
            item['roleId'] = item.ROLE_ID
            item['roleName'] = item.ROLE_NAME
          })
          const departGmsList = []

          const positionId = this.groupEditSearch.positionId
          debugger
          const data = {
            dataSource: '10451003',
            dataType: '10461002',
            positionCode: this.groupEditSearch.positionCode,
            positionName: this.groupEditSearch.positionName,
            organizationId: this.groupEditSearch.organizationId,
            positionLevel: this.groupEditSearch.positionLevel,
            isSyncBeidi: this.groupEditSearch.isSyncBeidi,
            departGmsList: departGmsList,
            roleGmsSelectList: roleGmsSelectList
          }
          editSavePositionAuth(positionId, data).then(res => {
            this.$message({
              type: 'success',
              message: '保存成功!'
            })
            this.active = 1
            this.searchHandle()
          }).catch(err => {
            this.$message({
              type: 'error',
              message: err.response.data.errorMsg
            })
            return false
          })
        } else {
          this.$message({
            type: 'info',
            message: '请填写必填项!'
          })
          return false
        }
      })
    },
    // 集团返回清空列表
    clear() {
      this.activeName = 'first'
      this.groupAddSearch.positionCode = ''
      this.groupAddSearch.positionName = ''
      const groupAddTable1 = this.$refs['groupAddTable1']
      groupAddTable1.filData(this.returnList)
      const groupEditTable1 = this.$refs['groupEditTable1']
      groupEditTable1.filData(this.returnList)

      this.active = 1
    },

    // 新增组织选择
    getDepartmentOrgTree(val) {
      console.dir(val)

      this.groupAddSearch.orgName = val.label
      this.groupAddSearch.orgId = val.id
      this.groupAddSearch.organizationId = val.id
      this.groupAddSearch.orgType = val.orgType
    },
    // 编辑组织选择
    getDepartmentOrgEditTree(val) {
      this.groupEditSearch.orgName = val.label
      this.groupEditSearch.orgId = val.id
      this.groupEditSearch.organizationId = val.id
      this.groupEditSearch.orgType = val.orgType
    }
  }
}

</script>

<style scoped>

</style>
